#ifndef _TRACE_LOG_H
#define _TRACE_LOG_H

#include <cstring>
//最大的日志描述字符数
#define TRACE_LOG_MAX_DESCRIPTION_SIZE 4096


//日志等级
enum eTraceLogLevel
{
    //调用
    TRACE_LOG_LEVEL_CALL = 100,

    //调试
    TRACE_LOG_LEVEL_DEBUG = 200,

    //信息
    TRACE_LOG_LEVEL_INFO = 300,

    //警告
    TRACE_LOG_LEVEL_WARNING = 400,

    //错误
    TRACE_LOG_LEVEL_ERROR = 500,

    //意外
    TRACE_LOG_LEVEL_UNEXPECTED = 600,

    //异常
    TRACE_LOG_LEVEL_EXCEPTION = 700,

    //致命
    TRACE_LOG_LEVEL_FATAL = 800,
};


//注册一个模块
//参数1：模块名称字符串
//返回模块指针
//#define MAKE_LOG_MODULE(name) CTraceLog::GetInstance()->RegisterTraceLogModule(name)

#define MAKE_LOG_MODULE(name) nullptr

//日志接口单字节版本
//参数1：模块指针，可以为空
//参数2：eTraceLogLevel枚举量
//参数3：格式化字符串
//#define TRACE_LOG_A(ptr, level, fmt, ...)   CTraceLog::GetInstance()->WriteLogA(ptr, level, "[%s()][%d]:"##fmt,  __FUNCTION__, __LINE__, __VA_ARGS__)
//#define TRACE_LOG_A(ptr, level, fmt, ...)   CTraceLog::GetInstance()->WriteLogA(ptr, level, fmt, ##__VA_ARGS__)

void EbsLogPrint(void *ptr, int level, char *cTmp);

#define GET_FILENAME(path) (strrchr(path, '/') ? strrchr(path, '/') + 1 : path)

#define TRACE_LOG_A(ptr, level, fmt, ...)                                                                                               \
    do {                                                                                                                                \
        char cTmp[TRACE_LOG_MAX_DESCRIPTION_SIZE + 1] = {0};                                                                            \
        const char *filename = GET_FILENAME(__FILE__);                                                                                  \
        snprintf(cTmp, TRACE_LOG_MAX_DESCRIPTION_SIZE, "[EBS|%s|%s()|Line:%d]:" #fmt, filename, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
        EbsLogPrint(ptr, level, cTmp);                                                                                                  \
    } while (0)

#define TRACE_LOG_W TRACE_LOG_A


#endif
